package com.doit.day03

object _04_不可变数组 {
  def main(args: Array[String]): Unit = {
    //定义
    val arr: Array[Int] = Array(1, 2, 3, 4, 5)
    val arr1: Array[Int] = new Array[Int](6)
    //获取索引对应的元素值
    val i: Int = arr(1)
    //增删改查
    //更新元素
    arr.update(0,3)

    val newArray: Array[Int] = arr.drop(2)
    println(arr.mkString(","))//3,2,3,4,5
    println(newArray.mkString(","))//3,4,5  从左到右删除了两个元素
    println(arr.sum)//17
    println(arr.max)//5
    println(arr.min)//2

    val ints: Array[Int] = arr.take(1)
    println(ints.mkString(","))//3
    val ints1: Array[Int] = arr.take(2)
    println(ints1.mkString(","))//3,2

    //3,2,3,4,5
    println(arr.head)//3
    val tail: Array[Int] = arr.tail
    println(tail.mkString(","))//2,3,4,5

    println(arr.last)//5

    val ints2: Array[Int] = arr.+:(6) //: 当做原来的数组
    println(ints2.mkString(","))//6,3,2,3,4,5
    val ints3: Array[Int] = arr.:+(7)
    println(ints3.mkString(","))//3,2,3,4,5,7


    val ints4: Array[Int] = arr.++(ints3)
    println(ints4.mkString(","))//3,2,3,4,5,3,2,3,4,5,7

    val ints5: Array[Int] = arr.++:(ints3)
    println(ints5.mkString(","))//3,2,3,4,5,7,3,2,3,4,5


    //交集   3,2,3,4,5   3,2,3,4,5,7
    println(arr.intersect(ints3).mkString(","))//3,2,3,4,5      3,2,3,4,5
    //差集
    println(ints3.diff(arr).mkString(","))//3,2,3,4,5 7
    //并集
    println(arr.union(ints3).mkString(","))//3,2,3,4,5,3,2,3,4,5,7   3,2,3,4,5,3,2,3,4,5,7







  }
}
